//
//  UIButton+Util.swift
//  爱限免
//
//  Created by 曲晨阳的MacBook on 16/9/26.
//  Copyright © 2016年 QCY. All rights reserved.
//

import UIKit

extension UIButton
{
    class func createButton(frame: CGRect, title: String?, bgImageName: String?, target: AnyObject?, action: Selector) -> UIButton
    {
        let button = UIButton(type: .Custom)
        button.frame = frame
        if let tmpTitle = title
        {
            button.setTitle(tmpTitle, forState: .Normal)
            button.setTitleColor(UIColor.blackColor(), forState: .Normal)
        }
        
        if let bgImageName = bgImageName
        {
            button.setBackgroundImage(UIImage(named: bgImageName), forState: .Normal)
        }
        
        if target != nil && action != nil
        {
            button.addTarget(target, action: action, forControlEvents: .TouchUpInside)
        }
        return button
    }
}
